package com.yanghui.lingyue.utils.functionUtils

import com.icedata.sika.bridge.*
import com.yanghui.lingyue.bot.Bot

object FunctionUtils {

    fun atBot(event: SikaGroupEvent): Boolean {
        if (!event.message.hasAtMessage)
            return false
        for (m in event.message) {
            if (m is SikaAtMessage) {
                if (m.target == Bot.sikaCore.config.qq)
                    return true
            }
        }
        return false
    }

    fun extractKeyword(event: SikaGroupEvent, keyword: String): String? {
        var messageContent = ""
        for (m in event.message) {
            if (m is SikaPlainMessage)
                messageContent += m.contentToString()
        }
        val param = messageContent.replace(keyword, "")
        if (messageContent.contains(keyword) and param.isNotEmpty()) {
            return param
        }
        return null
    }

}